package com.ruoyi.web.controller.purchase;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.domain.Classification;
import com.ruoyi.purchase.service.IClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * classificationController
 * 
 * @author ruoyi
 * @date 2025-08-24
 */
@RestController
@RequestMapping("/purchase/classification")
public class ClassificationController extends BaseController
{
    @Autowired
    private IClassificationService classificationService;

    /**
     * 查询classification列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:classification:list')")
    @GetMapping("/list")
    public TableDataInfo list(Classification classification)
    {
        startPage();
        List<Classification> list = classificationService.selectClassificationList(classification);
        return getDataTable(list);
    }

    /**
     * 导出classification列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:classification:export')")
    @Log(title = "classification", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Classification classification)
    {
        List<Classification> list = classificationService.selectClassificationList(classification);
        ExcelUtil<Classification> util = new ExcelUtil<Classification>(Classification.class);
        util.exportExcel(response, list, "classification数据");
    }

    /**
     * 获取classification详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:classification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(classificationService.selectClassificationById(id));
    }

    /**
     * 新增classification
     */
    @PreAuthorize("@ss.hasPermi('purchase:classification:add')")
    @Log(title = "classification", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Classification classification)
    {
        classification.setUserId(getUserId());
        classification.setUserName(getUsername());
        return toAjax(classificationService.insertClassification(classification));
    }

    /**
     * 修改classification
     */
    @PreAuthorize("@ss.hasPermi('purchase:classification:edit')")
    @Log(title = "classification", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Classification classification)
    {
        return toAjax(classificationService.updateClassification(classification));
    }

    /**
     * 删除classification
     */
    @PreAuthorize("@ss.hasPermi('purchase:classification:remove')")
    @Log(title = "classification", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classificationService.deleteClassificationByIds(ids));
    }
}
